/* eslint-disable class-methods-use-this */

import { ListAvatarDto, ListCityDto, UpdationChildV2Dto, UserWithProfileV2Dto } from '@/shared/interfaces/generated';
import request from '@api';

export class ProfileApi {
  async getProfile(id: number) {
    const ans = await request<UserWithProfileV2Dto>(`/users/${id}`, 'GET');
    return ans;
  }

  async editProfileAvatr(data: FormData) {
    const ans = await request('/user/profile', 'PATCH', data, { 'content-type': 'multipart/form-data' });
    return ans;
  }

  async editProfile(id: number, data: UpdationChildV2Dto | { name: null | string }) {
    const ans = await request(`/users/${id}/profile`, 'PATCH', data);
    return ans;
  }

  async getCities(search: string | '', limit = 20, offset?: number) {
    const params = new URLSearchParams();
    params.append('search', search);
    params.append('limit', String(limit));
    params.append('offset', String(offset || 0));
    const ans = await request<ListCityDto>(`/cities?${params.toString()}`, 'GET');
    return ans;
  }

  async getUniqueAvatarList() {
    const ans = await request<ListAvatarDto>('/avatars', 'GET');
    return ans;
  }

  async removeProfile(userId: number) {
    const ans = await request(`/users/${userId}`, 'DELETE');
    return ans;
  }
}
